import pandas as pd
import matplotlib.pyplot as plt
import random

# 生物种类列表（至少20个）
species = [
    'Plankton', 'Small Fish', 'Medium Fish', 'Big Fish', 'Squid', 'Shark', 'Whale',
    'Crab', 'Jellyfish', 'Seaweed', 'Starfish', 'Octopus', 'Dolphin', 'Turtle',
    'Seahorse', 'Anemone', 'Sea Urchin', 'Lobster', 'Seagull', 'Penguin', 'Manatee'
]

# 每种物种的数量，模拟基本食物链关系（以万为单位）
# 更高级物种的数量应该较低级物种的数量少，但这里只是简单模拟，并非真实数据
plankton = random.randint(50000, 100000)
small_fish = random.randint(30000, 80000)
medium_fish = random.randint(20000, 50000)
big_fish = random.randint(10000, 20000)
squid = random.randint(7000, 10000)
shark = random.randint(5000, 7000)
whale = random.randint(3000, 5000)
crab = random.randint(10000, 20000)
jellyfish = random.randint(10000, 30000)
seaweed = random.randint(20000, 50000)
starfish = random.randint(10000, 15000)
octopus = random.randint(7000, 8000)
dolphin = random.randint(5000, 7000)
turtle = random.randint(3000, 5000)
seahorse = random.randint(2000, 3000)
anemone = random.randint(1000, 3000)
sea_urchin = random.randint(1000, 4000)
lobster = random.randint(1000, 4000)
seagull = random.randint(1000, 4000)
penguin = random.randint(1000, 4000)
manatee = random.randint(1000, 4000)

quantities = [
    plankton, small_fish, medium_fish, big_fish, squid, shark, whale,
    crab, jellyfish, seaweed, starfish, octopus, dolphin, turtle,
    seahorse, anemone, sea_urchin, lobster, seagull, penguin, manatee
]

# 创建数据框
data = pd.DataFrame({
    'species': species,
    'quantity': quantities
})

# 保存数据到 CSV 文件
data.to_csv('data_resource\marine_eco_data.csv', index=False)
# 读取CSV文件
data = pd.read_csv('data_resource\marine_eco_data.csv')
# 绘制不同生物种类数量的条形图
plt.figure(figsize=(10, 6))
plt.bar(data['species'], data['quantity'])
plt.xlabel('species')
plt.ylabel('quantity')
plt.title('Marine ecological data')
plt.xticks(rotation=45)
plt.grid(True)
plt.show()
